#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
#include <SDL/SDL.h>




SDL_Surface* affichage;
SDL_Event event;

void initSDL(void);

int main(int argc, char** argv)
{
    int done=1, continuer = 1, *amp;
    initSDL();
    SDL_Surface *ecran=NULL, *image;
    SDL_Surface *score;
    SDL_Surface *regle;
    SDL_Surface *jouer;
    SDL_Surface *option;
    SDL_Surface *son;

    SDL_Rect  desti;
    SDL_Rect desti1;
    SDL_Rect desti2;
    SDL_Rect desti3;
    SDL_Rect desti4;



	atexit(SDL_Quit);
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		fprintf(stderr, "Echec d'initialisation de SDL.\n");
		return 1;
	}
	printf("SDL est initialisé avec succès.\n");
	ecran = SDL_SetVideoMode(960, 640, 32, SDL_ANYFORMAT|SDL_FULLSCREEN);
	if ( ecran == NULL )
	{
		printf("Echec de creation de la fenetre  : %s.\n");
		return 1;
	}

	/* Chargement du bitmap "image.bmp" en memoire dans la surface image */
	image = SDL_LoadBMP("fort.bmp");
	if ( image == NULL )
	{
		printf( "Echec de chargement du fichier image.bmp : %s.\n", SDL_GetError());
		return 1;
	}
	score = SDL_LoadBMP("bouton.bmp");
if (score == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
regle= SDL_LoadBMP("bouton.bmp");
if (regle== NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
jouer= SDL_LoadBMP("bouton.bmp");
if (jouer== NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
option = SDL_LoadBMP("bouton.bmp");
if (option == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
son = SDL_LoadBMP("bouton.bmp");
	if ( son == NULL )
	{
		printf( "Echec de chargement du fichier image.bmp : %s.\n", SDL_GetError());
		return 1;
	}
SDL_SetColorKey(score, SDL_SRCCOLORKEY, SDL_MapRGB(score->format, 255, 255, 255));
SDL_SetColorKey(regle, SDL_SRCCOLORKEY, SDL_MapRGB(regle->format, 255, 255, 255));
SDL_SetColorKey(jouer, SDL_SRCCOLORKEY, SDL_MapRGB(jouer->format, 255, 255, 255));
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(option->format, 255, 255, 255));
SDL_SetColorKey(son, SDL_SRCCOLORKEY, SDL_MapRGB(son->format, 255, 255, 255));


//Construct the destination rectangle for our blit
desti.x = 300;
desti.y = 450;
desti.w = score->w;
desti.h = score->h;
desti1.x = 300;
desti1.y = 330;
desti1.w = regle->w;
desti1.h = regle->h;
desti2.x = 300;
desti2.y = 205;
desti2.w = jouer->w;
desti2.h = jouer->h;
desti3.x = 790;
desti3.y = 540;
desti3.w = option->w;
desti3.h = option->h;
desti4.x = 785;
desti4.y = 50;
desti4.w = son->w;
desti4.h = son->h;
	SDL_BlitSurface(image, NULL, ecran,NULL);
	SDL_BlitSurface(score, NULL, ecran, &desti);
    SDL_BlitSurface(regle, NULL, ecran,&desti1 );
	SDL_BlitSurface(jouer, NULL, ecran, &desti2);
	SDL_BlitSurface(option, NULL, ecran, &desti3);
    SDL_BlitSurface(son, NULL, ecran, &desti4);


	SDL_UpdateRect(ecran, 0, 0, 0, 0);

	SDL_EnableKeyRepeat(10,10);
    while(done){
    while (SDL_PollEvent(&event))
{
    switch (event.type)
{

    case SDL_QUIT:
    done = 0;
    break;
    case SDL_KEYDOWN:
{

if (event.key.keysym.sym == SDLK_ESCAPE)
done = 0;
break;
}
}
}
}

   SDL_Init(SDL_INIT_VIDEO);

   ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
   SDL_Event event;
   SDL_WM_SetCaption("SDL_Mixer", NULL);
   SDL_Flip(ecran);
   if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
   {
      printf("%s", Mix_GetError());
   }
   Mix_Music *musique; //Création du pointeur de type Mix_Music
   musique = Mix_LoadMUS("musique.mp3"); //Chargement de la musique
   Mix_PlayMusic(musique, -1); //Jouer infiniment la musique
   while(continuer)
   {
      while (SDL_PollEvent(&event))
{
    switch (event.type)
{

    case SDL_QUIT:
            continuer = 0;
            break;
      }
   }
   Mix_FreeMusic(musique); //Libération de la musique
   Mix_CloseAudio(); //Fermeture de l'API
   SDL_Quit();
   return EXIT_SUCCESS;
}

  return EXIT_SUCCESS;
}

void initSDL(void)
{
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "Erreur à l'initialisation de la SDL : %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  }

  atexit(SDL_Quit);
  affichage = SDL_SetVideoMode(0, 0, 0, SDL_SWSURFACE | SDL_FULLSCREEN);

  if (affichage == NULL) {
    fprintf(stderr, "Impossible d'activer le mode graphique : %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  }

  SDL_WM_SetCaption("jeu de nime", NULL);
}

